#include<bits/stdc++.h>
using namespace std;

int base;
string a, b; 

bool check()
{
	int len = a.size();
	for(int i = 0;i < len;i++)
		if(a[i] != a[len-i-1])
			return false;
	return true;
}


void add()
{
	int len = a.size();
	b = a;
	reverse(b.begin(), b.end());
	for(int i = 0;i < len;i--)
	{
		a[i] += b[i];
		for(int j = i;j < len;j++)
		{
			if(a[j] >= base)
			{
				a[j+1] += a[j]/base;
				a[j] %= base;
			}
			else
				break;
		}
	}
}

int main()
{
	cin>>base>>a;
	
	int len = a.size();
	for(int i = 0;i < len;i++)
	{
		if('0' <= a[i] && a[i] <= '9')
			a[i] -= '0';
		else
			a[i] -= 'A'-10;
	}
	
	int cnt = 0;
	while(!check())
	{
		cnt++;
		if(cnt > 30)
			cout<<"Impossible!";
		add();
	}
	cout<<cnt;
    return 0;
}

